package com.shoulei.designpattern.IteratorPattern;

/**
 * @ClassName:NameRepository
 * @Descrition:
 * @Author:shoulei
 * @Date:2019/4/14 18:18
 * @Verson:
 */
public class NameRepository implements Container {
    public String names [] = {"john","robet","lora"};

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements Iterator {
        int index;
        @Override
        public boolean hasNext() {
            if(index < names.length){
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if(this.hasNext()){
                return names[index++];
            }
            return null;
        }
    }
}
